package com.cheer.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cheer.common.Result;
import com.cheer.param.ActivityCheckinParam;
import com.cheer.service.ActivityPartiService;
import com.cheer.service.ActivityService;
import com.cheer.service.AuthService;
import com.cheer.vo.ActivityInfoVO;
import com.cheer.vo.ActivityPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;


/**
 * @author cheer
 */
@RestController
@RequestMapping("/activity")
@Api(tags = "活动")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @Autowired
    private AuthService authService;

    @ApiOperation("团活动首页")
    @GetMapping("/page")
    public Result<IPage<ActivityPageVO>> page(Integer pageNum, Integer pageSize, HttpSession session) {
        IPage<ActivityPageVO> page = activityService.page(pageNum, pageSize, session);
        return Result.success(page);
    }

    @ApiOperation("活动详情")
    @GetMapping("/info")
    public Result<ActivityInfoVO> info(Integer id, HttpSession session) {

        Integer userId = authService.getUserId(session);
        ActivityInfoVO info = activityService.info(id, userId);
        return Result.success(info);
    }

    @ApiOperation(value = "点击报名" )
    @GetMapping("/registration")
    public Result<ActivityInfoVO> registration(Integer actId, HttpSession session) {
        Integer userId = authService.getUserId(session);
        activityService.registration(actId, userId);
        return Result.success();
    }

    @ApiOperation(value = "签到", notes = "获取签名接口：/auth/sign " +
            "计算距离参考: https://lbs.qq.com/service/webService/webServiceGuide/webServiceMatrix")
    @PostMapping("/checkin")
    public Result<ActivityInfoVO> checkin(@RequestBody ActivityCheckinParam activityCheckinParam, HttpSession session) {
        Integer userId = authService.getUserId(session);
        activityService.checkin(activityCheckinParam, userId);
        return Result.success();
    }


}
